<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      width: 400px;
      height: 60px;
      background-color: rgb(158, 97, 97);
      margin: 30px auto;
      color: #fff;
      font-size: 30px;
    }
  </style>
</head>
<body>
  <div id="app">
    <button @click="msg = 'hello world'">修改msg</button>
    {{ msg }}
    <hr>
    <button @click="addArr">增加li</button>
    <ul>
      <li v-for="item in arr" :key="item">
        {{ item }}
      </li>
    </ul>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data(){
        return {
          msg: 'hello vue3',
          arr: [1,2,3,4]
        }
      },
      methods: {
        addArr() {
          const oul = document.querySelector('ul');
          this.arr.push(this.arr.length+1);
        }
      },
      watch: {
        // 新增watch属性，侦听谁就定义同名方法即可
        msg(newVal, oldVal){
          console.log('msg修改了值是', newVal);
        },
        arr(newVal){
          console.log('arr改变了', newVal);
        }
      }
    })
    app.mount('#app')
  </script>
</body>
</html>